package com.xuedongzhilian.config;

import com.xuedongzhilian.utils.LoginInterceptor;
import com.xuedongzhilian.utils.RefreshTokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 拦截路径配置
 * order(0)：表示先执行
 * order(1)：表示后执行
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 登录拦截器
        registry.addInterceptor(new LoginInterceptor())
                // 放行路径
                .excludePathPatterns(
                        "/shop/**",
                        "/voucher/**",
                        "/shop-type/**",
                        "/upload/**",
                        "/blogs/**",
                        "/blog/hot",
                        "/user/code",
                        "/user/login",
                        "/user/manage/wechat/login",
                        "/user/me",
                        "/circle/**"
                ).order(1);
//      //   token刷新的拦截器,拦截所有请求
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
    }
}